<?php
namespace app\controllers;

use laiq\base\Controller;
use app\models\ItemModel;

class ItemController extends Controller
{
    public function index() {
        $keyword = isset($_GET['keyword']) ? $_GET['keyword'] : '';
        if ($keyword) {
            $items = (new ItemModel())->search($keyword);
        } else {
            $items = (new ItemModel())->where()->order(['id desc'])->fetchAll();
        }

        $this->assign('title', 'All Items');
        $this->assign('keyword', $keyword);
        $this->assign('items', $items);
        $this->render();
    }
}